<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

<ui:composition template="/restrito/principal.xhtml">
<ui:define name="titulo">
   	Cadastro de Obras
</ui:define>
<ui:define name="corpo">
<h:form id="listagem" prependId="false">
<p:growl /> 
<p:dataTable id="datatable" var="obra" value="#{obraBean.lista}"  
	sortBy="#{obra.cod_obra}" sortOrder="DESCENDING" 	
	widgetVar="obraTable" style="width:795px; margin-left:-10px;" paginator="true"
	paginatorPosition="bottom" rows="10" emptyMessage="Nenhuma obra encontrada!" 
	rowsPerPageTemplate="5,10,15" filteredValue="#{obraBean.lista}">	 
	<f:facet name="header">
		<p:commandButton value="Nova Obra" action="#{obraBean.novo}" />
		<h:outputText value="Pesquisar Obra: " style="margin-left:280px;"/>  
		<p:inputText id="globalFilter" onkeyup="obraTable.filter()" style="width:200px" filterPosition="left"/> 
	</f:facet>
	<p:column id="colunaCodigo" style="width:5px; text-align:center;"> 
		<f:facet name="header">
			<h:outputText value="Codigo"/> 
		</f:facet> 
		<h:outputText value="#{obra.cod_obra}" id="codigo"/>  
	</p:column> 
  		           		
	<p:column id="colunaDescricao" filterBy="#{obra.des_obra}" filterStyle="display:none" style="width:70px; text-align:center;" > 
		<f:facet name="header">
			<h:outputText value="Descrição Obra"/> 
		</f:facet> 
		<h:outputText value="#{obra.des_obra}" id="descricao"/>  
	</p:column> 
		           		
	<p:column  id="colunaEngenheiro" style="text-align:center;"> 
		<f:facet name="header"> 
			<h:outputText value="Engenheiro" /> 
		</f:facet> 
		<h:outputText value="#{obra.des_engenh}" id="engenheiro"/> 
	</p:column> 
		           		 
	<p:column  id="colunaValor" style="text-align:center;"> 
		<f:facet name="header"> 
			<h:outputText value="Valor Obra"/> 
		</f:facet> 
		<h:outputText value="#{obra.val_total_obra}" id="valor">
			<f:convertNumber pattern="#,##0.00" minFractionDigits="2" maxFractionDigits="2" />
		</h:outputText> 
	</p:column>

	<p:column id="colunaExcluir" style="width:10px; text-align:center;"> 
		<f:facet name="header"> 
			<h:outputText value="Excluir"/> 
		</f:facet>	                
		<p:commandLink action="#{obraBean.excluir}" onclick="if (!confirm('Confirma a exclusão da #{obra.des_obra}?')) return false;" update="datatable">
			<h:graphicImage library="imagens" name="excluir16.png" style="border:0;"/>
			<f:setPropertyActionListener target="#{obraBean.obra}" value="#{obra}"/>
		</p:commandLink>
	</p:column>

	<p:column id="colunaAlterar" style="width:10px; text-align:center;"> 
		<f:facet name="header"> 
			<h:outputText value="Alterar"/> 
		</f:facet>	                
		<p:commandLink action="#{obraBean.alterar}" update="datatable">
			<h:graphicImage library="imagens" name="editar16.png" style="border:0;"/>
			<f:setPropertyActionListener target="#{obraBean.obra}" value="#{obra}"/>
		</p:commandLink>
	</p:column>

	<p:column id="colunaAdicionar" style="width:10px; text-align:center;"> 
		<f:facet name="header"> 
			<h:outputText value="Opções"/> 
		</f:facet>	                
		<p:commandLink id="addObra" oncomplete="obraDialog.show()" update="@form">
			<h:graphicImage library="imagens" name="adicionar_arq16.png" style="border:0;"/>
			<f:setPropertyActionListener target="#{obraBean.obra}" value="#{obra}"/>
		</p:commandLink>
		<h:outputText value="&nbsp;&nbsp;"/>
		<p:commandLink id="visualizarObra" oncomplete="visualizarArq.show()" update="@form">
			<h:graphicImage library="imagens" name="eye.png" style="border:0;"/>
			<f:setPropertyActionListener target="#{obraBean.obra}" value="#{obra}"/>
		</p:commandLink>
	</p:column>	     		 
</p:dataTable>
<h:panelGrid columns="2"> 
<p:panel header="Exportar Página Atual" style="width:200px; margin-left:-12px;">
	<h:commandLink>  
		<p:graphicImage library="imagens" name="excel.png" style="border:none;" title="Exportar para Excel"/>  
	    <p:dataExporter type="xls" target="datatable" encoding="iso-8859-1" fileName="Relatório Obras" pageOnly="true" postProcessor="#{obraBean.PreparaXLS}"/>  
	</h:commandLink>  
			  
	<h:commandLink>  
		<p:graphicImage library="imagens" name="pdf.png" style="border:none;" title="Exportar para PDF" />  
		<p:dataExporter type="pdf" target="datatable" encoding="iso-8859-1" fileName="Relatório Obras" pageOnly="true" preProcessor="#{obraBean.PreparaPDF}"/>  
	</h:commandLink> 
</p:panel> 
</h:panelGrid>

<!-- Adicionar arquivos obra -->
<p:dialog header="Adicionar Arquivos" widgetVar="obraDialog" position="center" resizable="false" id="obraDlg" showEffect="fade"
	hideEffect="explode" modal="true" minWidth="600" minHeight="500">
<h:panelGrid id="infoObra" columns="2">
	<p:outputLabel value="Obra: " />
	<h:outputText value="#{obraBean.obra.des_obra}" />
	<p:outputLabel value="Arquivo: " />
	<h:panelGroup>
	<p:fileUpload fileUploadListener="#{obraBean.SalvarArquivos}"
		cancelLabel="Cancelar"
        label="Selecionar"
        invalidFileMessage="Tipo de imagem inválido"
        invalidSizeMessage="Imagem muito grande"
        uploadLabel="Enviar"
        allowTypes="/(\.|\/)(jpe?g|png)$/">
    </p:fileUpload>
	</h:panelGroup>
</h:panelGrid>
</p:dialog>

<p:dialog header="Listar Arquivos" widgetVar="visualizarArq" position="center" resizable="false" id="listaDlg" showEffect="fade"
	hideEffect="explode" modal="true" minWidth="600" minHeight="500">
<h:form>
<p:dataTable id="lstArquivo" var="arquivo" value="#{obraBean.listaArquivos}" sortBy="#{arquivo.cod_obra_arquiv}" 
style="width:795px; margin-left:-10px;" emptyMessage="Nenhum arquivo encontrado!">	 
	<p:column id="colCodigo" style="width:5px; text-align:center;"> 
		<f:facet name="header">
			<h:outputText value="Codigo"/> 
		</f:facet> 
		<h:outputText value="#{arquivo.cod_obra_arquiv}" id="codarquivo"/>  
	</p:column> 
  		           		
	<p:column id="colPasta" style="width:70px; text-align:center;" > 
		<f:facet name="header">
			<h:outputText value="Caminho arquivo"/> 
		</f:facet> 
		<h:outputText value="#{arquivo.des_pasta_arquiv}" id="pasta"/>  
	</p:column> 
</p:dataTable>
</h:form>
</p:dialog>
</h:form>
</ui:define>
</ui:composition> 
</html>
